package br.com.me.ceap;

import org.apache.cxf.jaxrs.client.WebClient;

/**
 * Created by Bruno Mendonça with IntelliJ IDEA.
 * User: brunol
 * Date: 14/10/11
 * Time: 12:33
 */
public class MECEAPUtils extends WebConnectionUtils {
// ------------------------------ FIELDS ------------------------------

    private static String MECEAP_BASE_CUSTOMCODE_API_PATH = "api/customcodes";

// -------------------------- STATIC METHODS --------------------------

    public static WebClient forUploadCustomCodeJAR(BaseMojo baseMojo, long timeoutUploadJAR) {
        WebClient webClient = createWebClient(baseMojo, String.format("%s/%s/%s", baseMojo.getUrl(), MECEAP_BASE_CUSTOMCODE_API_PATH, baseMojo.getCustomRootName()));
        setWebClientReceiveTimeout(webClient, timeoutUploadJAR);
        return webClient;
    }

    private static void setWebClientReceiveTimeout(WebClient webClient, long receiveTimeout) {
        WebClient.getConfig(webClient).getHttpConduit().getClient().setReceiveTimeout(receiveTimeout);
    }

    public static WebClient forUploadMappingFilesJAR(BaseMojo baseMojo, boolean cleanCustomRoot) {
        return createWebClient(baseMojo, String.format("%s/%s/%s/mappings/%s", baseMojo.getUrl(), MECEAP_BASE_CUSTOMCODE_API_PATH, baseMojo.getCustomRootName(), cleanCustomRoot));
    }

    public static WebClient forUploadDataFilesJAR(BaseMojo baseMojo, long receiveTimeout) {
        WebClient webClient = createWebClient(baseMojo, String.format("%s/%s/%s/data", baseMojo.getUrl(), MECEAP_BASE_CUSTOMCODE_API_PATH, baseMojo.getCustomRootName()));
        setWebClientReceiveTimeout(webClient, receiveTimeout);
        return webClient;
    }

    public static WebClient forDownloadCustomRootJAR(BaseMojo baseMojo) {
        return createWebClient(baseMojo, String.format("%s/%s/%s", baseMojo.getUrl(), MECEAP_BASE_CUSTOMCODE_API_PATH, baseMojo.getCustomRootName()));
    }

    public static WebClient forDownloadBPMNFilesJAR(BaseMojo baseMojo) {
        return createWebClient(baseMojo, String.format("%s/%s/%s/processes", baseMojo.getUrl(), MECEAP_BASE_CUSTOMCODE_API_PATH, baseMojo.getCustomRootName()));
    }

    public static WebClient forDownloadMappingJAR(BaseMojo baseMojo) {
        return createWebClient(baseMojo, String.format("%s/%s/%s/mappings", baseMojo.getUrl(), MECEAP_BASE_CUSTOMCODE_API_PATH, baseMojo.getCustomRootName()));
    }
}
